let connection = require('./dbHelpter');
module.exports = {
    // 添加参数：每页多少条pagesize，当前页nowPage
    getArticles: (pagesize, nowPage, cb) => {
        let sql = 'select articles.*,users.nickname from articles left join users on articles.userId=users.id limit ? offset ?;select count(*) as totalCount from articles;';
        // 公式:偏移量 = 每页多少条 *（当前页码 - 1）
        let offsetVal = pagesize * (nowPage - 1);
        connection.query(sql, [pagesize, offsetVal], (err, results) => {
            if (err) return cb(err, null);
            cb(null, results);
        });
    }
}